package com.test.market.controller;

import com.github.pagehelper.PageInfo;
import com.test.market.pojo.Bill;
import com.test.market.pojo.Supplier;
import com.test.market.service.BillService;
import com.test.market.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author 徒有琴
 */
@Controller
@RequestMapping("/bill")
public class BillController {
    @Autowired
    private BillService billService;
    @Autowired
    private SupplierService supplierService;

    @RequestMapping("/list.html")
    public String list(Bill bill, Integer pageNum, Model model) {
        if (pageNum == null || pageNum < 1) {
            pageNum = 1;
        }
        PageInfo<Bill> pageInfo = billService.getBillList(bill, pageNum, 2);
        List<Supplier> supplierList = supplierService.getSupplierList(null);
        model.addAttribute("pageInfo", pageInfo);
        model.addAttribute("supplierList", supplierList);
        return "bill_list";
    }
}
